// 全局加载组件
Component({
  properties: {
    globalLoading: {
      type: Boolean,
      value: false
    },
    globalLoadingText: {
      type: String,
      value: '加载中...'
    }
  },

  observers: {
    'globalLoadingText': function(newVal) {
      // 确保globalLoadingText不为null或undefined
      if (newVal === null || newVal === undefined) {
        this.setData({
          globalLoadingText: '加载中...'
        })
      }
    }
  },

  lifetimes: {
    attached() {
      // 组件初始化
      this.setData({
        globalLoading: false,
        globalLoadingText: '加载中...'
      })
    }
  },

  methods: {
    // 显示全局加载
    showGlobalLoading(text = '加载中...') {
      this.setData({
        globalLoading: true,
        globalLoadingText: text
      })
    },

    // 隐藏全局加载
    hideGlobalLoading() {
      this.setData({
        globalLoading: false
      })
    }
  }
})
